﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace tracker.ClassCommon
{

    public static class gpsExtensionMethod
    {
        public static DateTime convertGMTClientTime(this DateTime dt, string timezone)
        {
            if (timezone != null)
            {
                int iOut = 0;
                if (int.TryParse(timezone, out iOut))
                {
                    if (iOut > 780 || iOut < -720)
                    {
                        return dt;
                    }
                    else
                    {
                        return iOut % 15 == 0 ? dt.AddMinutes(iOut) : dt;
                    }
                }
                else
                {
                    return dt;
                }
            }
            else
                return dt;
        }

        public static DateTime convertGMTServerTime(this DateTime dt, string timezone)
        {
            if (timezone != null)
            {
                int iOut = 0;
                if (int.TryParse(timezone, out iOut))
                {
                    if (iOut > 780 || iOut < -720)
                    {
                        return dt;
                    }
                    else
                    {
                        return iOut % 15 == 0 ? dt.AddMinutes(-iOut) : dt;
                    }
                }
                else
                {
                    return dt;
                }
            }
            else
                return dt;
        }
    }
}